package org.koyad.portal.tags.core;

import java.util.Iterator;

import org.koyad.portal.annotations.TagCordinates;
import org.koyad.portal.constants.FrameworkConstants;
import org.koyad.portal.tags.AbstractTag;
import org.koyad.portal.tags.TagUtils;

@TagCordinates (
	uri = FrameworkConstants.CORE_NAMESPACE,
	localName = "iterate"
)
public class IterateTag extends AbstractTag {
	
	@Override
	public void render() {
		
		Object value = TagUtils.getValue(getAttributeValue("items"));
		if(value instanceof Iterable) {
			Iterator iter =	((Iterable)value).iterator();
			while(iter.hasNext()) {
				setValue(getAttributeValue("var"), iter.next(), true);
				renderBody();
			}
		} else {
			System.out.println("expression " + getAttributeValue("items") + " is not iterable");
		}
	}
	
}
